// $ANTLR 3.2 Sep 23, 2009 12:02:23 /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g 2010-11-14 18:28:10

package com.dynamicalsoftware.news.parser;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


import org.antlr.runtime.tree.*;

public class NewsRequestASTParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "STRING", "INT", "WS", "ESC_SEQ", "HEX_DIGIT", "UNICODE_ESC", "OCTAL_ESC", "'repository:'", "'topic:'", "'interest:'", "','", "'format:'", "'count:'"
    };
    public static final int ESC_SEQ=7;
    public static final int WS=6;
    public static final int T__16=16;
    public static final int T__15=15;
    public static final int T__12=12;
    public static final int T__11=11;
    public static final int T__14=14;
    public static final int T__13=13;
    public static final int UNICODE_ESC=9;
    public static final int OCTAL_ESC=10;
    public static final int HEX_DIGIT=8;
    public static final int INT=5;
    public static final int EOF=-1;
    public static final int STRING=4;

    // delegates
    // delegators


        public NewsRequestASTParser(TokenStream input) {
            this(input, new RecognizerSharedState());
        }
        public NewsRequestASTParser(TokenStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return NewsRequestASTParser.tokenNames; }
    public String getGrammarFileName() { return "/home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g"; }


    public static class ask_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "ask"
    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:15:1: ask : ( repository | topic | interests | format | count )+ ;
    public final NewsRequestASTParser.ask_return ask() throws RecognitionException {
        NewsRequestASTParser.ask_return retval = new NewsRequestASTParser.ask_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        NewsRequestASTParser.repository_return repository1 = null;

        NewsRequestASTParser.topic_return topic2 = null;

        NewsRequestASTParser.interests_return interests3 = null;

        NewsRequestASTParser.format_return format4 = null;

        NewsRequestASTParser.count_return count5 = null;



        try {
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:15:5: ( ( repository | topic | interests | format | count )+ )
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:16:2: ( repository | topic | interests | format | count )+
            {
            root_0 = (Object)adaptor.nil();

            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:16:2: ( repository | topic | interests | format | count )+
            int cnt1=0;
            loop1:
            do {
                int alt1=6;
                switch ( input.LA(1) ) {
                case 11:
                    {
                    alt1=1;
                    }
                    break;
                case 12:
                    {
                    alt1=2;
                    }
                    break;
                case 13:
                    {
                    alt1=3;
                    }
                    break;
                case 15:
                    {
                    alt1=4;
                    }
                    break;
                case 16:
                    {
                    alt1=5;
                    }
                    break;

                }

                switch (alt1) {
            	case 1 :
            	    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:17:2: repository
            	    {
            	    pushFollow(FOLLOW_repository_in_ask43);
            	    repository1=repository();

            	    state._fsp--;

            	    adaptor.addChild(root_0, repository1.getTree());

            	    }
            	    break;
            	case 2 :
            	    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:19:2: topic
            	    {
            	    pushFollow(FOLLOW_topic_in_ask49);
            	    topic2=topic();

            	    state._fsp--;

            	    adaptor.addChild(root_0, topic2.getTree());

            	    }
            	    break;
            	case 3 :
            	    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:21:2: interests
            	    {
            	    pushFollow(FOLLOW_interests_in_ask55);
            	    interests3=interests();

            	    state._fsp--;

            	    adaptor.addChild(root_0, interests3.getTree());

            	    }
            	    break;
            	case 4 :
            	    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:23:2: format
            	    {
            	    pushFollow(FOLLOW_format_in_ask61);
            	    format4=format();

            	    state._fsp--;

            	    adaptor.addChild(root_0, format4.getTree());

            	    }
            	    break;
            	case 5 :
            	    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:25:2: count
            	    {
            	    pushFollow(FOLLOW_count_in_ask67);
            	    count5=count();

            	    state._fsp--;

            	    adaptor.addChild(root_0, count5.getTree());

            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);


            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "ask"

    public static class repository_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "repository"
    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:28:1: repository : 'repository:' STRING -> ^( 'repository:' STRING ) ;
    public final NewsRequestASTParser.repository_return repository() throws RecognitionException {
        NewsRequestASTParser.repository_return retval = new NewsRequestASTParser.repository_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token string_literal6=null;
        Token STRING7=null;

        Object string_literal6_tree=null;
        Object STRING7_tree=null;
        RewriteRuleTokenStream stream_STRING=new RewriteRuleTokenStream(adaptor,"token STRING");
        RewriteRuleTokenStream stream_11=new RewriteRuleTokenStream(adaptor,"token 11");

        try {
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:28:12: ( 'repository:' STRING -> ^( 'repository:' STRING ) )
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:29:2: 'repository:' STRING
            {
            string_literal6=(Token)match(input,11,FOLLOW_11_in_repository81);  
            stream_11.add(string_literal6);

            STRING7=(Token)match(input,STRING,FOLLOW_STRING_in_repository83);  
            stream_STRING.add(STRING7);



            // AST REWRITE
            // elements: STRING, 11
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 29:23: -> ^( 'repository:' STRING )
            {
                // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:29:26: ^( 'repository:' STRING )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(stream_11.nextNode(), root_1);

                adaptor.addChild(root_1, stream_STRING.nextNode());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "repository"

    public static class topic_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "topic"
    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:31:1: topic : 'topic:' STRING -> ^( 'topic:' STRING ) ;
    public final NewsRequestASTParser.topic_return topic() throws RecognitionException {
        NewsRequestASTParser.topic_return retval = new NewsRequestASTParser.topic_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token string_literal8=null;
        Token STRING9=null;

        Object string_literal8_tree=null;
        Object STRING9_tree=null;
        RewriteRuleTokenStream stream_STRING=new RewriteRuleTokenStream(adaptor,"token STRING");
        RewriteRuleTokenStream stream_12=new RewriteRuleTokenStream(adaptor,"token 12");

        try {
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:31:7: ( 'topic:' STRING -> ^( 'topic:' STRING ) )
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:32:2: 'topic:' STRING
            {
            string_literal8=(Token)match(input,12,FOLLOW_12_in_topic104);  
            stream_12.add(string_literal8);

            STRING9=(Token)match(input,STRING,FOLLOW_STRING_in_topic106);  
            stream_STRING.add(STRING9);



            // AST REWRITE
            // elements: STRING, 12
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 32:18: -> ^( 'topic:' STRING )
            {
                // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:32:21: ^( 'topic:' STRING )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(stream_12.nextNode(), root_1);

                adaptor.addChild(root_1, stream_STRING.nextNode());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "topic"

    public static class interests_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "interests"
    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:34:1: interests : 'interest:' STRING ( ',' STRING )* -> ^( 'interest:' ( STRING )+ ) ;
    public final NewsRequestASTParser.interests_return interests() throws RecognitionException {
        NewsRequestASTParser.interests_return retval = new NewsRequestASTParser.interests_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token string_literal10=null;
        Token STRING11=null;
        Token char_literal12=null;
        Token STRING13=null;

        Object string_literal10_tree=null;
        Object STRING11_tree=null;
        Object char_literal12_tree=null;
        Object STRING13_tree=null;
        RewriteRuleTokenStream stream_13=new RewriteRuleTokenStream(adaptor,"token 13");
        RewriteRuleTokenStream stream_14=new RewriteRuleTokenStream(adaptor,"token 14");
        RewriteRuleTokenStream stream_STRING=new RewriteRuleTokenStream(adaptor,"token STRING");

        try {
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:34:11: ( 'interest:' STRING ( ',' STRING )* -> ^( 'interest:' ( STRING )+ ) )
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:35:2: 'interest:' STRING ( ',' STRING )*
            {
            string_literal10=(Token)match(input,13,FOLLOW_13_in_interests126);  
            stream_13.add(string_literal10);

            STRING11=(Token)match(input,STRING,FOLLOW_STRING_in_interests128);  
            stream_STRING.add(STRING11);

            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:35:21: ( ',' STRING )*
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==14) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:35:23: ',' STRING
            	    {
            	    char_literal12=(Token)match(input,14,FOLLOW_14_in_interests132);  
            	    stream_14.add(char_literal12);

            	    STRING13=(Token)match(input,STRING,FOLLOW_STRING_in_interests134);  
            	    stream_STRING.add(STRING13);


            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);



            // AST REWRITE
            // elements: 13, STRING
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 35:37: -> ^( 'interest:' ( STRING )+ )
            {
                // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:35:40: ^( 'interest:' ( STRING )+ )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(stream_13.nextNode(), root_1);

                if ( !(stream_STRING.hasNext()) ) {
                    throw new RewriteEarlyExitException();
                }
                while ( stream_STRING.hasNext() ) {
                    adaptor.addChild(root_1, stream_STRING.nextNode());

                }
                stream_STRING.reset();

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "interests"

    public static class format_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "format"
    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:37:1: format : 'format:' STRING -> ^( 'format:' STRING ) ;
    public final NewsRequestASTParser.format_return format() throws RecognitionException {
        NewsRequestASTParser.format_return retval = new NewsRequestASTParser.format_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token string_literal14=null;
        Token STRING15=null;

        Object string_literal14_tree=null;
        Object STRING15_tree=null;
        RewriteRuleTokenStream stream_15=new RewriteRuleTokenStream(adaptor,"token 15");
        RewriteRuleTokenStream stream_STRING=new RewriteRuleTokenStream(adaptor,"token STRING");

        try {
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:37:8: ( 'format:' STRING -> ^( 'format:' STRING ) )
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:38:2: 'format:' STRING
            {
            string_literal14=(Token)match(input,15,FOLLOW_15_in_format158);  
            stream_15.add(string_literal14);

            STRING15=(Token)match(input,STRING,FOLLOW_STRING_in_format160);  
            stream_STRING.add(STRING15);



            // AST REWRITE
            // elements: STRING, 15
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 38:19: -> ^( 'format:' STRING )
            {
                // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:38:22: ^( 'format:' STRING )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(stream_15.nextNode(), root_1);

                adaptor.addChild(root_1, stream_STRING.nextNode());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "format"

    public static class count_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "count"
    // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:40:1: count : 'count:' INT -> ^( 'count:' INT ) ;
    public final NewsRequestASTParser.count_return count() throws RecognitionException {
        NewsRequestASTParser.count_return retval = new NewsRequestASTParser.count_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token string_literal16=null;
        Token INT17=null;

        Object string_literal16_tree=null;
        Object INT17_tree=null;
        RewriteRuleTokenStream stream_INT=new RewriteRuleTokenStream(adaptor,"token INT");
        RewriteRuleTokenStream stream_16=new RewriteRuleTokenStream(adaptor,"token 16");

        try {
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:40:7: ( 'count:' INT -> ^( 'count:' INT ) )
            // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:41:2: 'count:' INT
            {
            string_literal16=(Token)match(input,16,FOLLOW_16_in_count180);  
            stream_16.add(string_literal16);

            INT17=(Token)match(input,INT,FOLLOW_INT_in_count182);  
            stream_INT.add(INT17);



            // AST REWRITE
            // elements: 16, INT
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 41:15: -> ^( 'count:' INT )
            {
                // /home/glenn/web/NewsWidget/src/com/dynamicalsoftware/news/parser/NewsRequestAST.g:41:18: ^( 'count:' INT )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(stream_16.nextNode(), root_1);

                adaptor.addChild(root_1, stream_INT.nextNode());

                adaptor.addChild(root_0, root_1);
                }

            }

            retval.tree = root_0;
            }

            retval.stop = input.LT(-1);

            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "count"

    // Delegated rules


 

    public static final BitSet FOLLOW_repository_in_ask43 = new BitSet(new long[]{0x000000000001B802L});
    public static final BitSet FOLLOW_topic_in_ask49 = new BitSet(new long[]{0x000000000001B802L});
    public static final BitSet FOLLOW_interests_in_ask55 = new BitSet(new long[]{0x000000000001B802L});
    public static final BitSet FOLLOW_format_in_ask61 = new BitSet(new long[]{0x000000000001B802L});
    public static final BitSet FOLLOW_count_in_ask67 = new BitSet(new long[]{0x000000000001B802L});
    public static final BitSet FOLLOW_11_in_repository81 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_STRING_in_repository83 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_12_in_topic104 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_STRING_in_topic106 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_13_in_interests126 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_STRING_in_interests128 = new BitSet(new long[]{0x0000000000004002L});
    public static final BitSet FOLLOW_14_in_interests132 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_STRING_in_interests134 = new BitSet(new long[]{0x0000000000004002L});
    public static final BitSet FOLLOW_15_in_format158 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_STRING_in_format160 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_16_in_count180 = new BitSet(new long[]{0x0000000000000020L});
    public static final BitSet FOLLOW_INT_in_count182 = new BitSet(new long[]{0x0000000000000002L});

}